frontend: Dialog: move useCallback before early return to fix rules-of-hooks#5208
Conversation
|
/lgtm |
There was a problem hiding this comment.
Pull request overview
This PR fixes an ESLint react-hooks/rules-of-hooks violation in DialogTitle by ensuring useCallback is always invoked before any early returns, and updates the hook dependencies to match referenced props.
Changes:
- Move the
focusedRefReact.useCallbackabove the guard-clause early return inDialogTitle. - Add
focusTitleto theuseCallbackdependency array (previously missing).
illume
left a comment
There was a problem hiding this comment.
Sorry, another PR was merged and there's now a git conflict.
Are you able to fix the git conflict?
|
New changes are detected. LGTM label has been removed. |
|
@illume fixed! |
19c7021 to
b596018
Compare
illume
left a comment
There was a problem hiding this comment.
Thanks for these changes.
Can you please have a look at the git commits to see if they meet the contribution guidelines? We use a Linux kernel style of git commits. See the contributing guide for general context, and please see previous git commits with git log for examples.
Commit guidelines
- Use atomic commits focused on a single change.
- Use the title format
<area>: <description of changes>. - Keep the title and body lines under 72 characters.
- Explain the intention and why the change is needed.
- Make commit titles meaningful and describe what changed.
- Do not add code that a later commit rewrites; squash or reorder commits instead.
- Do not include
Fixes #NNin commit messages.
Good examples:
frontend: HomeButton: Fix so it navigates to homebackend: config: Add enable-dynamic-clusters flag
Can you please address the open review comments?
b596018 to
943aff7
Compare
943aff7 to
1a3555e
Compare
The focusedRef useCallback in DialogTitle was called after a guard clause early return, violating rules-of-hooks. Move it before the early return so the hook is always called unconditionally. Also type the ref callback parameter as HTMLElement | null and simplify the null check, and add focusTitle to the dependency array which was previously missing.
1a3555e to
8c74ef6
Compare
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: illume, jedbillyb The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixes #5186
Moves
React.useCallbackinDialogTitleto before the early returnguard clause, satisfying rules-of-hooks. Also adds
focusTitleto thedependency array which was previously missing.
Steps to test:
npx eslint src/components/common/Dialog.tsx- no rules-of-hooks warnings